package com.suray.basic.wcs.plc.pojo.oper;

import com.suray.basic.wcs.plc.core.PlcOffset;
import com.suray.basic.wcs.plc.enums.PlcDeviceType;
import com.suray.basic.wcs.plc.enums.Location;
import com.suray.basic.wcs.plc.pojo.DeviceBase;
import com.suray.basic.wcs.utils.Coord;

/**
 * @author shaozn
 * @date 2020/1/22 - 14:22
 * @Description 拆叠盘机
 */
public class DismountingDiskMachineOper extends DeviceBase {

    private static final PlcOffset PALLET_NO = new PlcOffset(0, null);
    private static final PlcOffset EMPTY_PALLET = new PlcOffset(1, null);
    private static final PlcOffset PALLET_NUM = new PlcOffset(2, null);
    private static final PlcOffset PALLET_EXIST = new PlcOffset(3, 8);
    private static final PlcOffset LIFT_RUNING = new PlcOffset(3, 9);
    private static final PlcOffset LIFT_ERROR = new PlcOffset(3, 10);

    private static final PlcOffset LEFT_FORK_RUNING = new PlcOffset(3, 11);
    private static final PlcOffset LEFT_FORK_ERROR = new PlcOffset(3, 12);
    private static final PlcOffset RIGHT_FORK_RUNING = new PlcOffset(3, 13);
    private static final PlcOffset RIGHT_FORK_ERROR = new PlcOffset(3, 14);
    private static final PlcOffset CHAIN_RUNING = new PlcOffset(3, 15);

    private static final PlcOffset CHAIN_ERROR = new PlcOffset(3, 0);
    private static final PlcOffset UPPER_LIMIT = new PlcOffset(3, 1);
    private static final PlcOffset MEDIAN_LIMIT = new PlcOffset(3, 2);
    private static final PlcOffset LOWER_LIMIT = new PlcOffset(3, 3);
    private static final PlcOffset LEFT_FORK_EXTENSION_LIMIT = new PlcOffset(3, 4);

    private static final PlcOffset LEFT_FORK_SHRINKAGE_LIMIT = new PlcOffset(3, 5);
    private static final PlcOffset RIGHT_FORK_EXTENSION_LIMIT = new PlcOffset(3, 6);
    private static final PlcOffset RIGHT_FORK_SHRINKAGE_LIMIT = new PlcOffset(3, 7);

    /**
     * 工位任务编号
     */
    private Integer palletNo;
    /**
     * 是否已发生空托盘申请
     */
    private boolean emptyPallet;
    /**
     * 工位托盘数量
     */
    private Integer palletNum;
    /**
     * 工位是否有货
     */
    private boolean palletExist;
    /**
     * 拆码盘机（升降机构）运行状态
     */
    private boolean liftRuning;
    /**
     * 拆码盘机（升降机构）故障状态
     */
    private boolean liftError;
    /**
     * 拆码盘机（左叉）运行状态
     */
    private boolean leftForkRuning;
    /**
     * 拆码盘机（左叉）故障状态
     */
    private boolean leftForkError;
    /**
     * 拆码盘机（右叉）运行状态
     */
    private boolean rightForkRuning;
    /**
     * 拆码盘机（右叉）故障状态
     */
    private boolean rightForkError;
    /**
     * 拆码盘机（链条/辊道）运行状态
     */
    private boolean chainRuning;
    /**
     * 拆码盘机（链条/辊道）故障状态
     */
    private boolean chainError;
    /**
     * 拆码盘机（升降机构）位置状态（上限位）
     */
    private boolean upperLimit;
    /**
     * 拆码盘机（升降机构）位置状态（中限位）
     */
    private boolean medianLimit;
    /**
     * 拆码盘机（升降机构）位置状态（下限位）
     */
    private boolean lowerLimit;
    /**
     * 拆码盘机（左叉）位置状态（伸限位）
     */
    private boolean leftForkExtensionLimit;
    /**
     * 拆码盘机（左叉）位置状态（缩限位）
     */
    private boolean leftForkShrinkageLimit;
    /**
     * 拆码盘机（右叉）位置状态（伸限位）
     */
    private boolean rightForkExtensionLimit;
    /**
     * 拆码盘机（右叉）位置状态（缩限位）
     */
    private boolean rightForkShrinkageLimit;

    public DismountingDiskMachineOper(PlcDeviceType plcDeviceType, int startNo, String deviceName, int deviceNo, Coord coord,
                                      Location location, Coord lockLocation, long deviceId, Integer gridzMax,
                                      Integer gridzRelative, int plcId) {
        super(plcDeviceType, startNo, deviceName, deviceNo, coord, location, lockLocation,deviceId,gridzMax,
                gridzRelative, plcId);
    }

    public Integer getPalletNo() {
        return readPlc(PALLET_NO);
    }

    /**
     * 托盘数量
     *
     * @return
     */
    public Integer getPalletNum() {
        return readPlc(PALLET_NUM);
    }

    public boolean isEmptyPallet() {
        return readPlc(EMPTY_PALLET) == 1;
    }

    public boolean isPalletExist() {
        return readPlc(PALLET_EXIST) == 1;
    }

    public boolean isLiftRuning() {
        return readPlc(LIFT_RUNING) == 1;
    }

    public boolean isLiftError() {
        return readPlc(LIFT_ERROR) == 1;
    }

    public boolean isLeftForkRuning() {
        return readPlc(LEFT_FORK_RUNING) == 1;
    }

    public boolean isLeftForkError() {
        return readPlc(LEFT_FORK_ERROR) == 1;
    }

    public boolean isRightForkRuning() {
        return readPlc(RIGHT_FORK_RUNING) == 1;
    }

    public boolean isRightForkError() {
        return readPlc(RIGHT_FORK_ERROR) == 1;
    }

    public boolean isChainRuning() {
        return readPlc(CHAIN_RUNING) == 1;
    }

    public boolean isChainError() {
        return readPlc(CHAIN_ERROR) == 1;
    }

    public boolean isUpperLimit() {
        return readPlc(UPPER_LIMIT) == 1;
    }

    public boolean isMedianLimit() {
        return readPlc(MEDIAN_LIMIT) == 1;
    }

    public boolean isLowerLimit() {
        return readPlc(LOWER_LIMIT) == 1;
    }

    public boolean isLeftForkExtensionLimit() {
        return readPlc(LEFT_FORK_EXTENSION_LIMIT) == 1;
    }

    public boolean isLeftForkShrinkageLimit() {
        return readPlc(LEFT_FORK_SHRINKAGE_LIMIT) == 1;
    }

    public boolean isRightForkExtensionLimit() {
        return readPlc(RIGHT_FORK_EXTENSION_LIMIT) == 1;
    }

    public boolean isRightForkShrinkageLimit() {
        return readPlc(RIGHT_FORK_SHRINKAGE_LIMIT) == 1;
    }
}
